package com.woniuxy.microgoodsserver.auctionmag.controller;

import com.github.pagehelper.PageInfo;
import com.slsupermarket.common.res.ResponseMsg;
import com.woniuxy.microgoodsserver.auctionmag.service.GoodsBrandService;
import com.woniuxy.microgoodsserver.auctionmag.service.GoodsService;
import com.woniuxy.microgoodsserver.bean.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/goodsBrand")
public class GoodsBrabdController {

    @Resource
    GoodsBrandService goodsBrandService;

    @RequestMapping(value = "/brandFindAllById",produces = {"application/json;charset=utf-8"})
    public GoodsBrandBean brandFindAllById(int id){
        System.out.println(id);
        GoodsBrandBean goodsBrandBean = goodsBrandService.brandFindById(id);
        return goodsBrandBean;
    }

    @RequestMapping(value = "/brandFindAll",produces = {"application/json;charset=utf-8"})
    public PageInfo<GoodsBrandBean> brandFindAll(PageRequest pageRequest, GoodsBrandBean goodsBrandBean){
        System.out.println(pageRequest);
        System.out.println(goodsBrandBean);
        PageInfo<GoodsBrandBean> goodsBrandBeans = goodsBrandService.brandFindAll(pageRequest,goodsBrandBean);
        return goodsBrandBeans;
    }

    @RequestMapping(value = "/saveBrand",produces = {"application/json;charset=utf-8"})
    public ResponseMsg saveBrand(GoodsBrandBean goodsBrandBean){
        int a = goodsBrandService.savaBrand(goodsBrandBean);
        if (a<0){
            return ResponseMsg.builder().code(200).data(false).msg("成功").build();
        }
        return ResponseMsg.builder().code(200).data(true).msg("成功").build();
    }

    @RequestMapping(value = "/updateBrand",produces = {"application/json;charset=utf-8"})
    public ResponseMsg updateBrand(GoodsBrandBean goodsBrandBean){
        int a = goodsBrandService.updateBrand(goodsBrandBean);
        if (a<0){
            return ResponseMsg.builder().code(200).data(false).msg("成功").build();
        }
        return ResponseMsg.builder().code(200).data(true).msg("成功").build();
    }
}
